package com.tongzhou.tongzhou.link.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.link.dao.ILinkDAO;
import com.tongzhou.tongzhou.link.model.Degree;
import com.tongzhou.tongzhou.link.model.Link;
import com.tongzhou.tongzhou.link.model.SearchLinkCondition;

public class LinkAction extends ActionSupport{
	private int id;
	private int productSchedule_id;
	private Link link;
	private List<Link> result=null;
	private List<Degree> degreeResult=null;
	private SearchLinkCondition condition=null;
	
	private int pageSize ;
	private int currentPage ;
	private String orderBy ;
	private String orderByType ;
	private String keng;
	private String itemsVal;//度字符串
	
	private ILinkDAO dao=null;
	/**
	 * 生产线列表界面
	 *@author: 彭定雄
	 *@return 
	 *@throws DBException
	 */
	public String listLink() throws DBException{
		checkSearchCondition();
		condition = new SearchLinkCondition();
		if (currentPage == 0){
			currentPage = 1;
		}
		condition.setCurrentPage(currentPage) ;
		condition.setOrderBy(orderBy);
		condition.setOrderByType(orderByType) ;
		condition.setPageSize(pageSize) ;
		if(link==null){
			condition.setProductSchedule_id(productSchedule_id);
		}else{
			condition.setProductSchedule_id(link.getProductSchedule_id());
		}
	    result = dao.listLink(condition);
		return "listLink";
	} 
	
	
	/**
	 * 设置列表显示格式
	 *@author: 彭定雄
	 */
	private void checkSearchCondition(){
		if(currentPage <=0){
			currentPage = 1 ;
		}
		
		if(pageSize<=0){
			pageSize = 10 ;
		}
		
		if(orderBy==null||"".equals(orderBy)){
			orderBy = "id" ;
		}
		
		if(orderByType == null || "".equals(orderByType)){
			orderByType = "desc" ;
		}
	}
	
	/**
	 * 新增生产线
	 *@author: 彭定雄
	 *@return
	 *@throws DBException
	 */
	public String toAddLink() throws DBException{
		return "addLink";
	}
	
	public String addLink() throws DBException{
		dao.addLink(link,itemsVal);
		listLink();
		return "listLink";
	}
	
	public String deleteLink() throws DBException{
		dao.deleteLink(id);
		listLink();
		return "listLink";
	}
	
	public String toEditLink() throws DBException{
		link=dao.getLinkById(id);
		degreeResult=dao.getDegreeByLinkId(id);
		return "editLink";
	}
	
	public String editLink() throws DBException{
		dao.updateLink(link,itemsVal);
		listLink();
		return "listLink";
	}

	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public int getProductSchedule_id() {
		return productSchedule_id;
	}


	public void setProductSchedule_id(int productScheduleId) {
		productSchedule_id = productScheduleId;
	}


	public Link getLink() {
		return link;
	}


	public void setLink(Link link) {
		this.link = link;
	}


	public List<Link> getResult() {
		return result;
	}


	public void setResult(List<Link> result) {
		this.result = result;
	}


	public List<Degree> getDegreeResult() {
		return degreeResult;
	}


	public void setDegreeResult(List<Degree> degreeResult) {
		this.degreeResult = degreeResult;
	}


	public SearchLinkCondition getCondition() {
		return condition;
	}


	public void setCondition(SearchLinkCondition condition) {
		this.condition = condition;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public String getOrderBy() {
		return orderBy;
	}


	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}


	public String getOrderByType() {
		return orderByType;
	}


	public void setOrderByType(String orderByType) {
		this.orderByType = orderByType;
	}


	public String getKeng() {
		return keng;
	}


	public void setKeng(String keng) {
		this.keng = keng;
	}


	public ILinkDAO getDao() {
		return dao;
	}


	public void setDao(ILinkDAO dao) {
		this.dao = dao;
	}


	public String getItemsVal() {
		return itemsVal;
	}


	public void setItemsVal(String itemsVal) {
		this.itemsVal = itemsVal;
	}
}
